package com.example.myapplication2;

import android.content.res.Configuration;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class ScreenRotationActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen_rotation);
        System.out.println("onCreate");
    }
//配置项目变更的时候触发
    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        System.out.println("onConfigurationChanged");
        switch (newConfig.orientation){
            case Configuration.ORIENTATION_PORTRAIT:
                System.out.println("竖屏方向");
                break;
            case Configuration.ORIENTATION_LANDSCAPE:
                System.out.println("横屏方向");
                break;
            default:
                System.out.println("其他变更");
                break;
        }
        System.out.println(newConfig.orientation);
    }
}